package com.josework.springhelloworld.model.factory;


import com.baomidou.mybatisplus.core.conditions.ISqlSegment;
import com.josework.springhelloworld.entity.Apple;

import java.nio.file.DirectoryStream;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;

public class ProductFactory {
    final static Map<String,Supplier<Product>> map = new HashMap<>();

    final static Map<String,TriFunction<Integer,Integer,String,Product>> map2 = new HashMap<>();

    static {
        map.put("loan",Loan::new);
        map.put("stock",Stock::new);
        map.put("bond",Bond::new);
        map2.put("loan",Loan::new);
        map2.put("stock", Stock::new);
        map2.put("bond",Bond::new);
    }

    public static Product createProduct(String name){
        Supplier<Product> p = map.get(name);
        if (p!=null) return p.get();
        throw new IllegalArgumentException("No such product " + name);

    }

    public static Product createProduct(String name,TriFunction<Integer, Integer, String, Product> fun){
        TriFunction<Integer, Integer, String, Product> in = map2.get(name);
        in = fun;
        return fun.apply(2,3,"loanName");
    }




    public static void main(String[] args) {
//        Supplier<Product> loanSupplier = Loan::new;
//        Loan loan = (Loan) loanSupplier.get();
//        Product p = createProduct("cat");
//        p.printName();

        Runnable runnable = () -> {
        };

        ISqlSegment iSqlSegment = () -> "SELECT * FROM dbo.Product";
        ISqlSegment iSqlSegment1 = () -> {
            return "SELECT * FROM dbo.Student";
        };
        Function<Integer, String> integerStringFunction = (Integer i) -> {
            return i + "AI";
        };

        Function<String, String> stringStringFunction = (String s) -> {
            return "Product";
        };

        Function<String, String> stringStringFunction1 = (String s) -> {
            return s+" World";
        };
        String hello = stringStringFunction1.apply("Hello");


        Function<String, Integer> stringIntegerFunction = String::length;
        Integer hello1 = stringIntegerFunction.apply("hello");
        DirectoryStream.Filter<Apple> appleFilter = (Apple a) -> a.getWeight() > 50;
        Function<String, Integer> stringIntegerFunction1 = (String s) -> {
            return s.length();
        };
        Function<String, String> stringStringFunction2 = (String s) -> "hello" + s;
        String apply = stringStringFunction2.apply(" Tom");
        Runnable red = () -> new Apple("red", 100);
        Comparator<Apple> appleComparator = Comparator.comparingInt(Apple::getWeight);
        red.run();


    }
}
